import Vue from 'vue'
import VueRouter from 'vue-router'
import Router from 'vue-router'
import Register from '../views/Register.vue'//注册
import Verification from '../views/Verification.vue'//验证码
import Cipher from '../views/Cipher.vue'//修改密码
// import Index from '../views/Index.vue'//首页
// import Circle from '../views/Circle.vue'//泳圈
// import Find from '../views/Find.vue'//发现
// import Me from '../views/Me.vue'//我的
// import Member from '../views/Member.vue'//会员首页
// import Activity from '../views/Activity.vue'//活动首页
// import Membermore from '../views/Membermore.vue'//会员福利
// import Eventdetails from '../views/Eventdetails.vue'//活动详情
// import Opening from '../views/Opening.vue'//会员购买
// import Productdetails from '../views/Productdetails.vue'//商品列表
// import Details from '../views/Details.vue'//动态详情
// import Homepage from '../views/Homepage.vue'//个人资料修改
// import Join from '../views/Join.vue'//我的报名
// import Myplan from '../views/Myplan.vue'//我的计划
// import Already from '../views/Already.vue'//我的关注
// import Coachdetails from '../views/Coachdetails.vue'//教练详情页
// import Dynamic from '../views/Dynamic.vue'//发布动态
// import Train from '../views/Train.vue'//教练列表
// import Welfare from '../views/Welfare.vue'//我的福利
// import Order from '../views/Order.vue'//我的订单
// import Pdetails from '../views/Pdetails.vue'//店铺详情
// import Mymap from '../views/Mymap.vue'
// import Ddetails from '../views/Ddetails.vue'

Vue.use(VueRouter)
// 捕捉router错误
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
import { Dialog } from 'vant';
const routes = [
  {
    path: '/',
    name: 'Register',
    component: Register
  },
  {
    path: '/medal',
    name: 'Medal',
    component:()=>import(/*webpackChunkName:"medal"*/ '../views/Medal.vue'),
  },
  {
    path: '/cipher',
    name: 'Cipher',
    component: Cipher,
  },
  {
    path: '/search',
    name: 'Search',
    component:()=>import(/*webpackChunkName:"search"*/ '../views/Search.vue'),
  },
  {
    path: '/index',
    name: 'Index',
    component:()=>import(/*webpackChunkName:"index"*/ '../views/Index.vue'),
  },
  {
    path: '/ddetails',
    name: 'Ddetails',
    component:()=>import(/*webpackChunkName:"ddetails"*/ '../views/Ddetails.vue'),
  },
  {
    path: '/mymap',
    name: 'Mymap',
    component:()=>import(/*webpackChunkName:"mymap"*/ '../views/Mymap.vue'),
    props: true
  },
  {
    path: '/pdetails',
    name: 'Pdetails',
    component:()=>import(/*webpackChunkName:"pdetails"*/ '../views/Pdetails.vue'),
    props: true
  },
  {
    path: '/order',
    name: 'Order',
    component:()=>import(/*webpackChunkName:"order"*/ '../views/Order.vue'),
  },
  {
    path: '/welfare',
    name: 'Welfare',
    component:()=>import(/*webpackChunkName:"welfare"*/ '../views/Welfare.vue'),
  },
  {
    path: '/myplan',
    name: 'Myplan',
    component:()=>import(/*webpackChunkName:"myplan"*/ '../views/Myplan.vue'),
  },
  {
    path: '/train',
    name: 'Train',
    component:()=>import(/*webpackChunkName:"train"*/ '../views/Train.vue'),
  },
  {
    path: '/dynamic',
    name: 'Dynamic',
    component:()=>import(/*webpackChunkName:"dynamic"*/ '../views/Dynamic.vue'),
  },
  {
    path: '/coachdetails',
    name: 'Coachdetails',
    component:()=>import(/*webpackChunkName:"coachdetails"*/ '../views/Coachdetails.vue'),
  },
  {
    path: '/already',
    name: 'Already',
    component:()=>import(/*webpackChunkName:"already"*/ '../views/Already.vue'),
  },
  {
    path: '/join',
    name: 'Join',
    component:()=>import(/*webpackChunkName:"join"*/ '../views/Join.vue'),
  },
  {
    path: '/homepage',
    name: 'Homepage',
    component:()=>import(/*webpackChunkName:"homepage"*/ '../views/Homepage.vue'),
  },
  {
    path: '/details',
    name: 'Details',
    component:()=>import(/*webpackChunkName:"details"*/ '../views/Details.vue'),
    props: true
  },
  {
    path: '/detailsd',
    name: 'Detailsd',
    component:()=>import(/*webpackChunkName:"detailsd"*/ '../views/Detailsd.vue'),
    props: true
  },
  {
    path: '/productdetails',
    name: 'Productdetails',
    component:()=>import(/*webpackChunkName:"productdetails"*/ '../views/Productdetails.vue'),
  },
  {
    path: '/eventdetails',
    name: 'Eventdetails',
    component:()=>import(/*webpackChunkName:"eventdetails"*/ '../views/Eventdetails.vue'),
  },
  {
    path: '/opening',
    name: 'Opening',
    component:()=>import(/*webpackChunkName:"opening"*/ '../views/Opening.vue'),
  },
  {
    path: '/membermore',
    name: 'Membermore',
    component:()=>import(/*webpackChunkName:"membermore"*/ '../views/Membermore.vue'),
  },
  {
    path: '/activity',
    name: 'Activity',
    component:()=>import(/*webpackChunkName:"activity"*/ '../views/Activity.vue'),
  },
  {
    path: '/member',
    name: 'Member',
    component:()=>import(/*webpackChunkName:"member"*/ '../views/Member.vue'),
  },
  {
    path: '/me',
    name: 'Me',
    meta: { permission: true },
    component:()=>import(/*webpackChunkName:"me"*/ '../views/Me.vue'),
    beforeEnter:(to,from,next)=>{
      if(sessionStorage.getItem('islogin')){
        next();
      }else{
        Dialog({ message: '您还未登录，请先登录。' });
        next('/');
      }
    }
  },
  {
    path: '/find',
    name: 'Find',
    component:()=>import(/*webpackChunkName:"find"*/ '../views/Find.vue'),
  },
  {
    path: '/circle',
    name: 'Circle',
    component:()=>import(/*webpackChunkName:"circle"*/ '../views/Circle.vue'),
  },
  {
    path: '/verification/:phone',
    name: 'Verification',
    component: Verification,
    props: true
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = new VueRouter({
  routes
})

export default router
